import {Injectable} from '@angular/core';
import {LoginUser} from "../api";

@Injectable({
  providedIn: 'root'
})
export class JWTService {

  constructor(private loginUser: LoginUser) {
  }

  setHeaders(request: XMLHttpRequest) {
    if (this.loginUser.jwt) {
      request.setRequestHeader('Authorization', this.loginUser.jwt);
    }
  }

  openWindow(url: string) {
    if (url.indexOf('?') < 0) {
      url += '?';
    }
    window.open(url + '&Authorization=' + this.loginUser.jwt, 'blank');
  }

}
